package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingProjectController
 * @Author loe
 * @Date 2024-07-06
 */

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页条件查询
     * @param name 护理项目名称
     * @param pageNum 当前页码
     * @param pageSize 每页显示条数
     * @param status 状态（0：禁用，1：启用）
     * @return 结果(空)
     */
    @GetMapping
    @ApiOperation(value = "分页条件查询")
    public ResponseResult<PageResponse<NursingProjectVo>> limitSearch(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "当前页码") Integer pageNum,
            @ApiParam(value = "每页显示条数") Integer pageSize,
            @ApiParam(value = "状态（0：禁用，1：启用）") Integer status) {
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.limitSearch(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto 护理项目实体Dto
     * @return 成功(空)
     */
    @PostMapping
    @ApiOperation(value = "新增护理项目")
    public ResponseResult create(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.create(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查找
     * @param id 主键id
     * @return 成功(护理项目实体Vo)
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查找")
    public ResponseResult<NursingProjectVo> getById(
            @ApiParam(value = "主键id") @PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    /**
     * 编辑护理项目
     * @param nursingProjectDto 护理项目实体Dto
     * @return 成功(空)
     */
    @PutMapping
    @ApiOperation(value = "编辑护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    /**
     * 启用禁用
     * @param id 主键id
     * @param status 状态（0：禁用，1：启用）
     * @return 成功(空)
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult updateStatus(
            @ApiParam(value = "主键id") @PathVariable Long id,
            @ApiParam(value = "状态（0：禁用，1：启用）") @PathVariable Integer status
    ) {
        nursingProjectService.updateStatus(id, status);
        return success();
    }

    /**
     * 根据id删除护理项目
     * @param id 主键id
     * @return 成功(空)
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseResult deleteById(
            @ApiParam(value = "主键id") @PathVariable Long id
    ) {
        nursingProjectService.deleteById(id);
        return success();
    }

    /**
     * 查询所有护理项目
     * @return 成功(护理项目实体Vo集合)
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> searchAll() {
        List<NursingProjectVo> voList = nursingProjectService.searchAll();
        return success(voList);
    }
}
